package lims.cloud.system.user;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import jakarta.persistence.Column;
import jakarta.persistence.Transient;
import lims.cloud.system.base.mybatis.IBaseEntity;
import lims.cloud.system.department.Department;
import lombok.*;

import java.time.LocalDate;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor(force = true)
@AllArgsConstructor
//@Entity(name = "lims_system_user")
@TableName("lims_system_user")
public class User extends IBaseEntity<User> {
    @Column(length = 20)
    private String name;
    @Column(length = 30, unique = true)
    private String username;
    @Column(length = 200)
    private String password;
    @Column(length = 50)
    private String email;
    @Column(length = 18)
    private String idCard;
    @Column(length = 10)
    private String workNo;
    @Column(length = 20)
    private String phone;
    @Column(length = 1)
    private String gender;
    @Column(length = 10)
    private String educationLevel;//学历
    @Column(length = 20)
    private String graduateSchool;//毕业学校
    @Column(length = 20)
    private String major;//专业
    @JsonDeserialize(using = LocalDateDeserializer.class)
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate graduateDate;//毕业日期
    private Long departmentId;
    @Transient
    @TableField(exist = false)
    private Department department;//员工部门对应的实体类
    @Column(length = 100)
    private String headImageUuid;//头像存入服务器时使用的关键字
    @Transient
    @TableField(exist = false)
    private String headImageUrl;//头像地址
    @Transient
    @TableField(exist = false)
    @Builder.Default
    private Boolean includeAfter = true;//根据部门查询员工时，是否包含下级部门
    @Transient
    @TableField(exist = false)
    private String token;


    public User toSafe() {
        this.setPassword(null);
        return this;
    }
}
